#ifndef DBOPERATE_H
#define DBOPERATE_H

#include <QString>
#include <QSqlDatabase>

enum Rule{
    Ordinary,
    Administrator,
    NotLogin
};

struct AccountInfo{
    int uuid;
    QString userName;
    QString password;
    Rule rule; //2 未注册 0 普通用户 1 管理员
    int firstLogin;

    void initData(){
        userName = "";
        password = "";
        rule = Rule::NotLogin;
        firstLogin = 0;
    }
};

struct AreaInfo{
    QString areaName;
    QString point;
    QString imagePath;
};

struct NodeInfo
{
    QString nodeName;
    QString ID;
    QString affiliatedArea;
    QString point;
};

struct LogInfo
{
    QString nodeName;
    QString affiliatedArea;
    QString ID;
    int eventType;
    QString eventDescription;
    QString date;
    QString op;
};

class DBOperate
{
public:
    DBOperate();
    bool createAccount(QString);
    bool deleteAccount(int);
    bool changePassword(int, QString);
    bool changeFirstLoginState(int, int);
    AccountInfo selectAccountInfo(QString, QString);
    QVector<AccountInfo> selectAccountsInfo();
    QVector<NodeInfo> selectNodes();
    void updateAreas(QVector<AreaInfo>);
    QVector<AreaInfo> selectAreas();
    void updateNodes(QVector<NodeInfo>);
    QVector<LogInfo> selectLogsInfo();
    bool insertLog(LogInfo);

private:
    void createTable();

private:
    QSqlDatabase db;
};

#endif // DBOPERATE_H
